Skip to content

Adding MinScore support to Linear Retriever #126238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

mridula-s109
Copy link
Contributor

This PR introduces support for the min_score parameter in the linear retriever. The min_score filter ensures that only documents with a relevance score above a specified threshold are retrieved, improving result quality and filtering out low-relevance matches.

Added min_score support in the linear retriever.
Updated the retrieval logic to apply the min_score threshold.
Based on an example from the Elasticsearch Guide (8.18), extended it to demonstrate min_score usage.

@mridula-s109 mridula-s109 added >enhancement auto-backport Automatically create backport pull requests when merged :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch :Search Relevance/Search Catch all for Search Relevance labels Apr 3, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @mridula-s109, I've created a changelog YAML for you.

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some stuff that triggered my spidey-senses. See also #124182

@@ -346,7 +359,22 @@ public Matches matches(LeafReaderContext context, int doc) throws IOException {

@Override
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
return combinedWeight.scorerSupplier(context);
ScorerSupplier supplier = combinedWeight.scorerSupplier(context);
if (minScore != DEFAULT_MIN_SCORE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Min score != rather than <=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we are just checking here if the user has provided a value? ie is it different from the default

@mridula-s109 mridula-s109 requested a review from Copilot May 27, 2025 20:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the min_score parameter to the linear retriever to filter out documents with low relevance scores. Key changes include updates to YML tests for various min_score scenarios, modifications to LinearRetrieverBuilder and associated test cases, and accompanying enhancements in RankDocsQueryBuilder and documentation.

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
x-pack/plugin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/linear/10_linear_retriever.yml Added new test cases for min_score functionality including default, negative, and zero thresholds.
x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilder.java Updated builder to support min_score filtering and validation (throwing error for negative values).
x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilderTests.java Added tests to verify the new min_score filtering behavior.
server/* Updated RankDocsQueryBuilder, RankDocsRetrieverBuilder, and related cluster tests to propagate and validate min_score.
docs/reference/elasticsearch/rest-apis/retrievers.md Extended documentation to describe the new min_score parameter.
docs/changelog/126238.yaml Changelog entry reflecting the enhancement.
Files not reviewed (1)
  • x-pack/plugin/rank-rrf/build.gradle: Language not supported
Comments suppressed due to low confidence (1)

docs/reference/elasticsearch/rest-apis/retrievers.md:296

  • [nitpick] Clarify in the documentation that the default min_score is set to Float.MIN_VALUE (a very small positive number) to effectively disable filtering, ensuring that users understand 0 is a valid threshold.
`min_score` :   (Optional, float)

@mridula-s109 mridula-s109 requested a review from Copilot May 27, 2025 21:28
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the min_score parameter in the linear retriever, enabling the filtering of documents based on a minimum relevance score. Key changes include:

  • Implementing min_score filtering and validation in the LinearRetrieverBuilder and propagated components.
  • Updating various unit, parsing, and integration tests to validate the new min_score behavior.
  • Documenting the changes in YAML tests and reference documentation.

Reviewed Changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
x-pack/plugin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/linear/10_linear_retriever.yml Updates YAML tests to include various min_score scenarios
x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilderTests.java Adds unit tests for min_score filtering behavior
x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilderParsingTests.java Updates parsing tests to propagate default min_score
x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/linear/MinMaxScoreNormalizer.java Adjusts normalization logic for scores, handling NaN values
x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilder.java Introduces min_score as part of the builder with validation and propagation
x-pack/plugin/rank-rrf/src/internalClusterTest/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverIT.java Enhances integration tests to verify behavior under multiple min_score conditions
server/src/test/java/org/elasticsearch/index/query/RankDocsQueryBuilderTests.java Adds tests verifying serialization, parsing, and filtering based on min_score
server/src/main/java/org/elasticsearch/search/retriever/rankdoc/RankDocsQuery.java Uses min_score when deciding final document scores
server/src/main/java/org/elasticsearch/search/retriever/RankDocsRetrieverBuilder.java Propagates min_score to the search source builder
server/src/main/java/org/elasticsearch/index/query/RankDocsQueryBuilder.java Updates builder to include min_score for filtering and serialization
server/src/main/java/org/elasticsearch/TransportVersions.java Introduces a new transport version for min_score support
docs/reference/elasticsearch/rest-apis/retrievers.md Documents the new min_score parameter and usage examples
docs/changelog/126238.yaml Lists the change for adding MinScore support
Files not reviewed (2)
  • x-pack/plugin/rank-rrf/build.gradle: Language not supported
  • x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilderTests.java.new: Language not supported
Comments suppressed due to low confidence (1)

x-pack/plugin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/linear/10_linear_retriever.yml:1219

  • The expected error message regex in the test does not match the exception message thrown by LinearRetrieverBuilder (which indicates '[min_score] must be greater than or equal to 0'). Update the regex or exception message so that they are consistent.
      catch: "/\[min_score\] must be greater than 0, was: -1\.0/"

@mridula-s109 mridula-s109 force-pushed the add_min_score_linear_retriever branch from d648579 to d27b67b Compare June 2, 2025 20:43
@mridula-s109 mridula-s109 force-pushed the add_min_score_linear_retriever branch from d27b67b to 13bce60 Compare June 2, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >enhancement :Search Relevance/Search Catch all for Search Relevance :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants